const successResponse = (res, data, message = 'Success', statusCode = 200, args) => {
    // 防止重复发送响应
    if (res.headersSent) {
        console.warn('警告: 尝试在响应已发送后再次发送响应');
        return;
    }
    //console.log('successResponse', data);
    res.status(statusCode).json({
        code: 0, // Assuming 0 for success as per your spec
        message,
        data, ...args
    });
};

const errorResponse = (res, message, statusCode = 400, errorCode = -1) => {
    // 防止重复发送响应
    if (res.headersSent) {
        console.warn('警告: 尝试在响应已发送后再次发送响应');
        return;
    }
    // errorCode can be custom internal codes
    res.status(statusCode).json({
        code: errorCode !== -1 ? errorCode : statusCode,
        message,
    });
};

module.exports = {successResponse, errorResponse};
